﻿namespace PugLib.Extensions
{
	using System;
	using System.ComponentModel;
	using System.Diagnostics.CodeAnalysis;

	public static class EventExtensions
	{
		[SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate")]
		public static void Raise(this EventHandler handler, Object sender, EventArgs e)
		{
			EventHandler eventHandler = handler;
			if (eventHandler != null)
			{
				eventHandler(sender, e);
			}
		}

		[SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate")]
		public static void Raise<T>(this EventHandler<T> handler, Object sender, T e) where T : EventArgs
		{
			EventHandler<T> eventHandler = handler;
			if (eventHandler != null)
			{
				eventHandler(sender, e);
			}
		}

		[SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate")]
		public static void Raise<T>(this PropertyChangedEventHandler handler, Object sender, T e) where T : PropertyChangedEventArgs
		{
			PropertyChangedEventHandler eventHandler = handler;
			if (eventHandler != null)
			{
				eventHandler(sender, e);
			}
		}
	}
}